require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../utils/util"));

var t = require("../../../mybehaviors/location/location"), e = getApp();

Page({
    behaviors: [ t ],
    data: {
        info: "",
        rechargeNum: 1,
        config_info: {
            switch: 0
        },
        presentershow: !1,
        showRechargePay: !1,
        multiple_use: {
            is_open: !1,
            nums: 0
        },
        content: "",
        share_coupon: "",
        showSelect: !1,
        couponId: "",
        storeCoupon: null,
        active: 0,
        store_page: 1,
        store_isLoadMore: !0,
        store_total_page: 0,
        store_list: [],
        isLoadMore: !0,
        goods_page: 1,
        total_page: 0,
        goods_list: [],
        point: {
            lng: "",
            lat: ""
        },
        couponNum: "",
        combine: !1,
        is_shop: !1
    },
    onLoad: function(t) {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        }), console.log(t), t.id && this.setData({
            couponId: t.id
        }), t.combine && "undefined" != t.combine_show && this.setData({
            combine: t.combine
        }), "false" != t.combine_show && "undefined" != t.combine_show || (this.data.couponNum = 1), 
        this.init(), this.getdetail();
    },
    toStore: function(t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + e
        });
    },
    toGoodsStore: function(t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + e
        });
    },
    tapShare: function() {
        this.setData({
            showSelect: !0
        });
    },
    init: function() {
        this.setData({
            showSelect: !1,
            showPresenter: !1,
            verification: !1,
            shareNum: 1
        });
    },
    shareConfirm: function() {
        if (this.data.shareNum > this.data.multiple_use.nums) wx.showToast({
            title: "分享张数不足，最多".concat(this.data.multiple_use.nums, "张"),
            icon: "none",
            duration: 1e3
        }); else {
            this.setData({
                couponNum: this.data.shareNum
            });
            var t = {
                couponNum: this.data.couponNum
            };
            this.data.combine && "undefined" != this.data.combine && (t.combine = this.data.combine), 
            wx.navigateTo({
                url: "/packageI/CouponShareShow/CouponShareShow?info=" + JSON.stringify(t) + "&id=" + this.data.couponId
            });
        }
    },
    closeShare: function() {
        this.setData({
            showSelect: !1
        });
    },
    shareMunTap: function(t) {
        console.log(t), this.setData({
            shareNum: t.detail
        });
    },
    presenter: function(t, e) {
        console.log(t, this.info), this.setData({
            "usermessage.value": "",
            "usermessage.item": "",
            "usermessage.index": "",
            memberInfo: ""
        }), this.setData({
            "usermessage.item": t,
            "usermessage.index": e,
            presentershow: !0
        });
    },
    onclose: function(t) {
        this.setData({
            "usermessage.value": "",
            "usermessage.item": "",
            "usermessage.index": ""
        }), this.setData({
            presentershow: !1
        });
    },
    usermesbut: function(t) {
        var e = t.detail.value;
        this.setData({
            "usermessage.value": e
        });
    },
    usermesbutInput: function(t) {
        var e = t.detail.value;
        this.data.usermessage.value = e;
    },
    onconfirm: function(t) {
        if (console.log(this.data.usermessage), e._isTextEmpty(this.data.usermessage.value)) return wx.showToast({
            icon: "none",
            title: "用户ID不能为空",
            duration: 1e3
        }), void this.setData({
            presentershow: !1
        });
        "查无此用户" != this.data.memberInfo ? this.data.config_info.switch ? this.setData({
            showRechargePay: !0
        }) : this._presenterPost() : wx.showToast({
            icon: "none",
            title: "查询不到该用户ID，请确认无误!",
            duration: 1e3
        });
    },
    onPageScroll: function(t) {},
    _presenterPost: function() {
        var t = this, a = e.getNetAddresss("coupon.coupon-transfer.index");
        a += "&recipient=" + this.data.usermessage.value, a += "&record_id=" + this.data.couponId, 
        this.data.config_info.switch ? (a += "&quantity=" + this.data.rechargeNum, a += "&coupon_id=" + this.data.couponId) : a += "&transfer_num=" + this.data.rechargeNum, 
        e._getNetWork({
            url: a,
            success: function(e) {
                var a = e.data;
                if (1 == a.result) {
                    if (t.data.config_info.switch) return void wx.navigateTo({
                        url: "/packageD/buy/orderPay/orderPay?order_id=" + a.data.order_ids + "&status=2"
                    });
                    wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1e3,
                        success: function(e) {
                            t.data.combine ? (t.setData({
                                couponNum: t.data.couponNum - 1
                            }), setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1e3)) : setTimeout(function() {
                                wx.navigateBack({
                                    delta: 1
                                });
                            }, 1e3);
                        }
                    }), t.setData({
                        presentershow: !1
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                }), t.setData({
                    presentershow: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getmemberInfo: function(t) {
        var a = t.detail.value, o = this, s = e.getNetAddresss("member.member.memberInfo");
        s += "&uid=" + a, e._getNetWork({
            url: s,
            success: function(t) {
                var e = t.data;
                1 == e.result ? o.setData({
                    memberInfo: e.data ? e.data.nickname : "查无此用户"
                }) : o.setData({
                    memberInfo: "查无此用户"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getdetail: function() {
        var t = this, a = e.getNetAddresss("coupon.member-coupon.get-detail");
        a += "&record_id=" + this.data.couponId, e._getNetWork({
            url: a,
            success: function(a) {
                var o = a.data;
                if (1 == o.result) {
                    t.setData({
                        datainfo: o.data.coupon,
                        rule: o.data.rule,
                        img_url: o.data.img_url,
                        isPresenter: o.data.transfer
                    });
                    var s = o.data.coupon_fee_plugin;
                    s && (s.switch = parseInt(s.switch)), o.data.coupon_fee_plugin && t.setData({
                        config_info: s
                    }), o.data.multiple_use && t.setData({
                        couponNum: o.data.multiple_use.nums,
                        multiple_use: o.data.multiple_use
                    }), o.data.coupon && (t.setData({
                        content: o.data.coupon.content
                    }), 9 != o.data.coupon.use_type && 4 != o.data.coupon.use_type && 5 != o.data.coupon.use_type || (t._getLocation(function(e) {
                        t.data.point.lat = e.ad_info.location.lat, t.data.point.lng = e.ad_info.location.lng;
                    }), t.getCouponSetting())), o.data.share_coupon && t.setData({
                        share_coupon: o.data.share_coupon
                    });
                } else e.tips(o.msg);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCouponSetting: function() {
        var t = this, a = {
            coupon_id: this.data.datainfo.id,
            store_page: this.data.store_page,
            goods_page: this.data.goods_page,
            longitude: this.data.point.lng ? this.data.point.lng : "",
            latitude: this.data.point.lat ? this.data.point.lat : ""
        }, o = e.getNetAddresss("coupon.member-coupon.get-store-and-goods");
        e._postNetWork({
            url: o,
            data: a,
            success: function(a) {
                var o = a.data;
                1 == o.result ? (console.log(o), t.setData({
                    storeCoupon: o.data,
                    store_list: 0 == o.data.is_all_store ? o.data.store_list.data : o.data.store_list,
                    goods_list: 0 == o.data.is_all_good ? o.data.goods_list.data : o.data.goods_list,
                    is_shop: o.data.is_shop
                }), console.log(t.data.store_list, "ddddddddddddd"), o.data.is_shop || (1 == o.data.condition_type ? (console.log(o.data.goods_list), 
                t.setData({
                    isLoadMore: !0,
                    store_page: 1,
                    total_page: o.data.store_list.last_page,
                    store_list: o.data.store_list.data
                })) : t.setData({
                    isLoadMore: !0,
                    goods_page: 1,
                    total_page: o.data.goods_list.last_page,
                    store_isLoadMore: !0,
                    store_page: 1,
                    store_total_page: o.data.store_list.last_page
                }))) : e.tips(o.msg);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    initList: function(t) {
        this.setData({
            "storeCoupon.store_list.data": [],
            goods_list: [],
            isLoadMore: !0,
            goods_page: 1,
            total_page: 0,
            "storeCoupon.goods_list.data": [],
            store_list: [],
            store_isLoadMore: !0,
            store_page: 1,
            store_total_page: 0,
            active: t.detail.index
        }), this.getCouponSetting();
    },
    rentDeleteNumber: function() {
        if (this.data.rechargeNum - 1 <= 0) return wx.showToast({
            icon: "none",
            title: "转赠张数至少一张",
            duration: 1e3
        }), void this.setData({
            rechargeNum: 1
        });
        this.setData({
            rechargeNum: this.data.rechargeNum - 1
        });
    },
    rentAddNumber: function() {
        this.data.rechargeNum + 1 > this.data.multiple_use.nums ? e.tips("分享张数不足,当前可转赠数量为".concat(this.data.multiple_use.nums, "张")) : this.setData({
            rechargeNum: this.data.rechargeNum + 1
        });
    },
    changeRechargeNum: function(t) {
        Number(t.detail.value) > this.data.multiple_use.nums && (e.tips("分享张数不足,当前可转赠数量为".concat(this.data.multiple_use.nums, "张")), 
        this.setData({
            rechargeNum: this.data.multiple_use.nums
        }));
    },
    goBuy: function(t) {
        var e = this.data.datainfo;
        if (console.log(e), 0 == e.use_type) this.goHome(); else if (1 == e.use_type) {
            if (32 == e.plugin_id) return void wx.navigateTo({
                url: "/packageC/o2o/StoreSearch/StoreSearch?store_id=" + e.storeids + "&cid=" + e.category_ids
            });
            wx.navigateTo({
                url: "/packageB/member/category/catelist/catelist?id=" + JSON.stringify(e.category_ids) + "&fromHome=1"
            });
        } else 2 == e.use_type || 8 == e.use_type ? 32 == e.plugin_id ? wx.navigateTo({
            url: "/packageC/o2o/StoreSearch/StoreSearch?store_id=" + e.storeids + "&goods_ids=" + e.goods_ids.join(",")
        }) : wx.navigateTo({
            url: "/packageB/member/category/search_v2/search_v2?coupon=" + e.id + "&fromHome=1"
        }) : 4 === e.use_type && Array.isArray(e.storeids) ? wx.navigateTo({
            url: "/packageC/o2o/o2oHome/o2oHome"
        }) : 5 === e.use_type && "number" == typeof e.storeids ? wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + e.storeids
        }) : 7 === e.use_type && Array.isArray(e.hotel_ids) ? wx.navigateTo({
            url: "/packageC/hotel/HotelIndex/HotelIndex"
        }) : 6 === e.use_type && "number" == typeof e.hotel_ids ? wx.navigateTo({
            url: "/packageC/hotel/HotelHome/HotelHome?id=" + e.hotel_ids
        }) : this.goHome();
    },
    goHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    scrollChange: function(t) {
        console.log(t);
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            showSelect: !1
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getMoreData();
    },
    getMoreData: function() {
        var t = this;
        if (console.log(this.data.storeCoupon, "dddddd"), this.data.storeCoupon && (2 != this.data.storeCoupon.condition_type || 1 != this.data.storeCoupon.is_all_good && 1 != this.data.storeCoupon.is_all_good)) {
            var a = {
                coupon_id: this.data.datainfo.id,
                longitude: this.data.point.lng ? this.data.point.lng : "",
                latitude: this.data.point.lat ? this.data.point.lat : "",
                store_page: this.data.store_page,
                goods_page: this.data.goods_page
            };
            if (this.data.isLoadMore = !1, this.data.store_isLoadMore = !1, console.log(this.data.active), 
            1 == this.data.active) {
                if (console.log(this.data.store_page, this.data.total_page), this.data.store_page >= this.data.store_total_page) return;
                this.data.store_page = this.data.store_page + 1, a.store_page = this.data.store_page;
            } else {
                if (console.log(this.data.goods_page, this.data.total_page), this.data.goods_page >= this.data.total_page) return;
                this.data.goods_page = this.data.goods_page + 1, a.goods_page = this.data.goods_page;
            }
            var o = e.getNetAddresss("coupon.member-coupon.get-store-and-goods");
            e._postNetWork({
                url: o,
                data: a,
                success: function(a) {
                    var o = a.data;
                    if (console.log(o, "ddddd"), 1 == o.result) {
                        var s = [];
                        0 == t.data.active ? (s = o.data.goods_list.data, t.setData({
                            isLoadMore: !0,
                            goods_list: t.data.goods_list.concat(s)
                        })) : (s = o.data.store_list.data, t.setData({
                            store_isLoadMore: !0,
                            store_list: t.data.store_list.concat(s)
                        }));
                    } else e.tips(o.msg);
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    tapMoreBtn: function() {
        0 == this.data.active ? wx.navigateTo({
            path: "/packageG/index/index"
        }) : 1 == this.data.active && wx.navigateTo({
            url: "/packageC/o2o/o2oHome/o2oHome"
        });
    },
    onShareAppMessage: function() {
        var t = wx.getStorageSync("nickname");
        return {
            path: "/packageA/member/coupon_v2/coupon_v2",
            title: "".concat(t, "向您分享了优惠券")
        };
    },
    onShareTimeline: function() {
        var t = wx.getStorageSync("nickname");
        return {
            title: "".concat(t, "向您分享了优惠券")
        };
    }
});